from rest_framework import serializers
from apps.headline.models import *
from apps.users.models import User


class ChannelsModelSerializers(serializers.ModelSerializer):
    class Meta:
        model = Channel
        fields = [
            'id',
            'name'
        ]


class UserArtclesModelSerializers(serializers.ModelSerializer):

    class Meta:
        model = Article
        fields = [
            'id',
            'title'
        ]


class UsersModelSerializers(serializers.ModelSerializer):
    articles = UserArtclesModelSerializers

    class Meta:
        model = User
        fields = '__all__'


# class ArticleSerializerSimple(serializers.ModelSerializer):
#
#     class Meta:
#         model = Article
#         fields = ("id", "title")



# class UserDetailSerializer(serializers.ModelSerializer):
#
#     articles = ArticleSerializerSimple(read_only=True, many=True)
#
#     class Meta:
#         model = User
#         fields = ('id', 'username','avatar','articles','fans')




class ArticleModelSerializers(serializers.ModelSerializer):
    # user = UserDetailSerializer()
    # comments = serializers.SerializerMethodField()
    # labels = serializers.SerializerMethodField()
    # collected_users = serializers.SerializerMethodField()

    class Meta:
        model = Article
        fields = '__all__'




class ArticleCommentSerializers(serializers.ModelSerializer):
    class Meta:
        model = Comment
        fields = '__all__'


class ArticleSerializerForCreate(serializers.ModelSerializer):
    image = serializers.CharField(required=False, default='',allow_blank=True)
    comment = ArticleCommentSerializers()

    class Meta:
        model = Article
        exclude = ('collected_users',)

